﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;


namespace DAL
{
	public class THEDAO:DALBase
	{
		public THEDAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPTHE"; }
			set { _SpName = value; }
		}
		public DataTable GetListTHE()
		{
			dt = new DataTable();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new THES(), null), ConvertClassToArray.GetValues(new THES(), 0));
				return dt;
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list THES"); }
		}
		public List<THES> GetListTHE(int? flag)
		{
			List<THES> benhnhanc = new List<THES>();
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new THES(), null), ConvertClassToArray.GetValues(new THES(), 0));
				benhnhanc = (List<THES>)ConvertDatatableToList.ConvertTo<THES>(dt);
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list THES"); }
			return benhnhanc;
		}
		public String CreatenewId()
		{
			String mathe = "";
			try
			{
				dt = new DataTable();
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new THES(), null), ConvertClassToArray.GetValues(new THES(), 1));
				mathe = dt.Rows[0]["MATHE"].ToString();

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Create new THES"); }
			return mathe;
		}
		public bool INSERT(THES cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Insert new THES"); }
		}
		public bool UPDATE(THES cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Update  THES"); }
		}
		public bool DELETE(THES cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Delete  THES"); }
		}
		public DataTable GETTHE(THES t)
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(t, null), ConvertClassToArray.GetValues(t, 5));
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list THES"); }
			return dt;
		} 

	}
}
